<?php

	//	what's theme file, what does its usage?
	//	what is ipos? constant
	
if (!defined('ipos')) die("You don't have permission to do that");
//$filmlist	=	$db->database("phimid,
//									tenphim,
//									tentienganh,
//									phimimg,
//									thoiluong,
//									chatluong,
//									viewed_day","film","$sql_where LIMIT $limit");
//var_dump($filmlist);die();
/**
 * Copyright 2014 GES, Inc. Filter
 * @author GES.HoangPV
 * @param string $type
 * @param int $limit
 * @param unknown_type $code what is code
 */
function ipos_film($type,$limit=8,$code='') {
	global $db;
	if($type == 'phim-new') {
		$sql_where	=	"phimid != 1 ORDER BY phimid DESC";
		$url_pages	=	'danh-sach/phim-moi.html';
		$onertitle	=	'Danh sÃ¡ch phim má»›i';
	}
	elseif($type == 'phim-le-new') {
		$sql_where	=	"phimbo = 0 ORDER BY phimtime DESC";
		$url_pages	=	'danh-sach/phim-le.html';
		$onertitle	=	'Phim láº» má»›i';
	}
	elseif($type == 'phim-bo-new') {
		$sql_where	=	"phimbo IN (1,2) ORDER BY phimtime DESC";	
		$url_pages	=	'danh-sach/phim-bo.html';
		$onertitle	=	'Phim bá»™ má»›i';
	}
	elseif($type == 'phim-chieu-rap') {
		$sql_where	=	"phimchieurap = 1 ORDER BY phimtime DESC";
		$url_pages	=	'danh-sach/phim-chieu-rap.html';
		$onertitle	=	'Phim chiáº¿u ráº¡p';
	}
	elseif($type == 'phim-de-cu') {
		$sql_where	=	"phimdecu = 1 ORDER BY phimtime DESC";
		$url_pages	=	'danh-sach/phim-de-cu.html';
		$onertitle	=	'Phim Ä‘á»� cá»­';
	}
	elseif($type == 'xem-nhieu-day') {
		$sql_where	=	"viewed_day > 0 ORDER BY viewed_day DESC";
		$url_pages	=	'danh-sach/phim-viewed.html';
		$onertitle	=	'Xem nhiá»�u trong ngÃ y';
	}
	elseif($type == 'xem-nhieu') {
		$sql_where	=	"viewed > 0 ORDER BY viewed DESC";
		$url_pages	=	'danh-sach/phim-viewed.html';
		$onertitle	=	'Xem nhiá»�u nháº¥t';
	}
	elseif($type == 'ngau-nhien') {
		$sql_where	=	"phimid != 1 ORDER BY RAND() DESC";
	}
	elseif($type == 'category') {
		$code			=	substr($code, 1);
		$code			=	substr($code,0,-1);
		$ex				=	explode(",",$code);
		$count			=	count($ex);
		if($count==1)
			$sql_where	=	"(theloai LIKE '%,$code,%' ) OR ";
		else {
			for($x=0;$x<$count;$x++) {
				$sql_where	.=	"(theloai LIKE '%,".$ex[$x].",%' ) OR ";
			}
		}
		
		$sql_where		=	substr($sql_where,0,-4);
		
		
		$sql_where	=	"$sql_where ORDER BY RAND() DESC";	
		$onertitle	=	'Phim cÃ¹ng thá»ƒ loáº¡i';
	}
	// begin
	$filmlist	=	$db->database("phimid,
									tenphim,
									tentienganh,
									phimimg,
									thoiluong,
									chatluong,
									viewed_day","film","$sql_where LIMIT $limit");
	if(in_array($type, array('xem-nhieu','xem-nhieu-day','phim-de-cu'))) {
		for($i=0;$i<count($filmlist);$i++) {
			$url_hdnew	=	url_link($filmlist[$i][1].'-'.$filmlist[$i][2],$filmlist[$i][0],'phim');
			$html	.=	'<li><img width="200" src="'.$filmlist[$i][3].'" alt="'.$filmlist[$i][1].'"><a iposmovie-id="L-'.$filmlist[$i][0].'" title="'.$filmlist[$i][1].' - '.$filmlist[$i][2].'" href="'.$url_hdnew.'"><h3>'.$filmlist[$i][1].'</h3></a><a iposmovie-id="L-'.$filmlist[$i][0].'" title="'.$filmlist[$i][1].' - '.$filmlist[$i][2].'" href="'.$url_hdnew.'"><span>'.$filmlist[$i][2].'</span></a></li>';
		}
	}else {
		for($i=0;$i<count($filmlist);$i++) {
			$url_hdnew	=	url_link($filmlist[$i][1].'-'.$filmlist[$i][2],$filmlist[$i][0],'phim');
			$filmtxt	=	get_data('film_info','phimtxt','phimid = '.$filmlist[$i][0]);
			if ($filmlist[$i][6] > '100' && $type !== 'phim-new') $icon_hot[$i] = '<span class="hotrap"></span>';
			$html	.=	'	
					<li>
						<div class="items">
						<a href="'.$url_hdnew.'">
						<span class="overlay"></span>
						'.$icon_hot[$i].'
							<img class="thumb" src="'.$filmlist[$i][3].'">
						</a>
						<div class="mode"><span class="time">'.$filmlist[$i][4].'</span><span class="quality">'.$filmlist[$i][5].'</span></div>
						<div class="data">
							<a title="'.$filmlist[$i][1].' - '.$filmlist[$i][2].'" href="'.$url_hdnew.'">
								<h3>'.cut($filmlist[$i][1],25).'</h3>
							</a>
						</div>
						<div class="f-description hide">
				<h3>'.cut($filmlist[$i][1],30).'</h3>
				<div class="below-title">
				<div>'.cut($filmlist[$i][2],30).' </div>
				<div>'.$filmlist[$i][4].' | '.$filmlist[$i][5].'</div>
				</div>
				<p>'.cut($filmtxt,400).'</p>
			</div>
						</div>
					</li>';
		 }
	}
	return	$html;
}

// user menu
/**
 * Copyright 2014 GES, Inc.
 * @author GES.HoangPV
 * display a menu
 */
function _UserMenu() {
	global $db;
	if($_SESSION["ipos_userid"]) {
		$user	=	$db->database("gold,timelimit,username,fullname","user","userid = '".$_SESSION["ipos_userid"]."'");
		$userN	=	$_SESSION["ipos_username"];
		$u_url	=	url_link($userN,$_SESSION["ipos_userid"],'thanh-vien');
		if($user[0][1]>NOW) {
			$gold_time	=	"<div>Háº¿t háº¡n sá»­ dá»¥ng: <span style=\"font-size:14px\">".(date("d/m/Y",$user[0][1]))."</span> lÃºc <span style=\"font-size:14px\">".(date("G:i:s",$user[0][1]))."</span></div>";
		}
		if (GOLD_OPEN == '1') { 
			$html	=	"<a href=\"?logout=1\">ThoÃ¡t</a><a href=\"$u_url\" class=\"items\">CÃ¡ nhÃ¢n 
		<div class=\"f-description hide\">
			<div>TÃ i khoáº£n: ".$user[0][2]." (".$user[0][3].")</div>
			".$gold_time."
			<div>TÃ i khoáº£n hiá»‡n cÃ³: <span style=\"font-size:14px\">".number_format($user[0][0])."</span> ".GOLD."</div>
		</div></a>"; 
		}else {
			$html = "<a href=\"?logout=1\">ThoÃ¡t</a><a href=\"$u_url\" class=\"items\">CÃ¡ nhÃ¢n</a>";
		}
	}else {
		$html	=	'<a href="javascript:_Register();">Ä�Äƒng kÃ½</a><a href="javascript:_Login();">Ä�Äƒng nháº­p</a>';
	}
	return $html;
}
?>